home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / XPK / Source / xpkmaster / xpkmaster.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-12  |  9.0 KB  |  260 lines

  1. #ifndef XPKMASTER_XPKMASTER_H
  2. #define XPKMASTER_XPKMASTER_H
  3.  
  4. /* Includeheader
  5.  
  6.     Name:        xpkmaster.h
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: xpkmaster.h 1.8 (12.04.97)
  9.     Author:        SDI
  10.     Distribution:    PD
  11.     Description:    Master library global definitions and declarations
  12.             and prototypes
  13.  
  14.  1.0   05.10.96 : first real version
  15.  1.1   27.12.96 : removed library protos - call now via library interface,
  16.      allows patching
  17.  1.2   30.01.97 : change of cchecksum proto
  18.  1.3   31.01.97 : checksum changed again
  19.  1.4   01.03.97 : added new flags
  20.  1.5   08.03.97 : changed XpkBuffer a bit
  21.  1.6   31.03.97 : some little corrections
  22.  1.7   02.04.97 : removed obsolete stuff
  23.  1.8   12.04.97 : added DebugTagList
  24. */
  25.  
  26. /* To disable PowerPacker support comment out the next line. */
  27. #define USE_POWERPACKER 1
  28.  
  29. #ifndef __MAXON__
  30.   #include <pragma/xpksub_lib.h>
  31.   #ifdef USE_POWERPACKER
  32.     #include <pragma/powerpacker_lib.h>
  33.   #endif
  34. #else
  35.   #include "SDI_xpksub.h"    // Stubs for xpksub and powerpacker
  36.   #define __asm
  37. #endif
  38.  
  39. #ifdef SUPPORT_A4
  40.   #define A4SUPP    ,a4
  41.   #define A4SUPP2    ,xbuf->xb_regA4
  42.   #define A4PROTO    ,register __a4 ULONG a4
  43. #else
  44.   #define A4SUPP
  45.   #define A4SUPP2
  46.   #define A4PROTO
  47. #endif
  48.  
  49. #define SDI_TO_ANSI
  50. #include "SDI_ASM_STD_protos.h"
  51.  
  52. #include <xpk/xpk.h>
  53. #include <xpk/xpksub.h>
  54.  
  55. #define ROUNDLONG(x)        (((x)+3)&(~3))    /* round to next longword */
  56. #define DEFAULTCHUNKSIZE    0x8000
  57.  
  58. #ifndef Min
  59.   #define Min(a,b) ((a) < (b) ? (a) : (b))
  60.   #define max(a,b) ((a) > (b) ? (a) : (b))
  61. #endif
  62.  
  63. #define CHUNKSIZE 50000
  64.  
  65. /* The structure used for I/O, special master library version */
  66. struct XpkMasterMsg {
  67.   ULONG  xmm_Type;        /* Read/Write/Alloc/Free/Abort        */
  68.   STRPTR xmm_Ptr;        /* The mem area to read from/write to    */
  69.   LONG   xmm_Size;        /* The size of the read/write        */
  70.   ULONG  xmm_IOError;        /* The IoErr() that occurred        */
  71.   ULONG  xmm_Reserved;        /* Reserved for future use        */
  72.   STRPTR xmm_Buf;        /* Specific to the internal hooks    */
  73.   LONG   xmm_Error;        /* The XPKERR that occurred        */
  74.   ULONG  xmm_BufLen;
  75.   ULONG  xmm_BufOfs;
  76.   ULONG  xmm_Len;
  77.   ULONG  xmm_Flags;
  78.   ULONG  xmm_FH;
  79.   ULONG  xmm_MemType;
  80. };
  81.  
  82. #define XIO_GETOUTBUF 1
  83.  
  84. #define XPKMF_SEEKABLE    0x0001    /* ALL chunks (-dict) are independent    */
  85. #define XPKMF_DICTCHUNK    0x0002    /* First chunk is a global dictionary    */
  86. #define XPKMF_FIXSPEED    0x0004    /* Speed is for A3000/25MHz/SCRAM/2.04    */
  87. #define XPKMF_NOCLOBBER    0x0008    /* Don't overwrite            */
  88.  
  89. /* These structures define the file format for compressed streams */
  90. struct XpkStreamHeader {
  91.   ULONG xsh_Pack;
  92.   ULONG xsh_CLen;
  93.   ULONG xsh_Type;
  94.   ULONG xsh_ULen;
  95.   UBYTE xsh_Initial[16];
  96.   UBYTE xsh_Flags;
  97.   UBYTE xsh_HChk;
  98.   UBYTE xsh_SubVrs;
  99.   UBYTE xsh_MasVrs;
  100. };
  101.  
  102. #define XPK_COOKIE 0x58504b46    /* 'XPKF' - ID for xsh_Pack */
  103.  
  104. #define XPKSTREAMF_LONGHEADERS  0x01    /* Use XpkLongLocHeaders    */
  105. #define XPKSTREAMF_PASSWORD     0x02    /* This file encoded        */
  106. #define XPKSTREAMF_EXTHEADER    0x04    /* Extended globhdr        */
  107.  
  108. struct XpkChunkHdrWord {
  109.   UBYTE xchw_Type;
  110.   UBYTE xchw_HChk;
  111.   UWORD xchw_CChk;
  112.   UWORD xchw_CLen;
  113.   UWORD xchw_ULen;
  114. };
  115.  
  116. struct XpkChunkHdrLong {
  117.   UBYTE xchl_Type;
  118.   UBYTE xchl_HChk;
  119.   UWORD xchl_CChk;
  120.   ULONG xchl_CLen;
  121.   ULONG xchl_ULen;
  122. };
  123.  
  124. typedef union {
  125.   struct XpkChunkHdrLong xch_Long;
  126.   struct XpkChunkHdrWord xch_Word;
  127. } XpkChunkHeader;
  128.  
  129. #define XPKCHUNK_TYPE        0x0f
  130. #define XPKCHUNK_RAW        0x00
  131. #define XPKCHUNK_PACKED        0x01
  132. #define XPKCHUNK_FDATA        0x02 /* Protection bits, file comment ... */
  133. #define XPKCHUNK_END        0x0f
  134.  
  135. #define XPKCHUNKF_ENTRYPOINT    0x80 /* Stream can be seeked to at this point */
  136.  
  137. struct Headers {
  138.   struct XpkStreamHeader h_Glob;
  139.   XpkChunkHeader     h_Loc;
  140.   ULONG             h_LocSize;
  141. };
  142.  
  143. #define XPKMODE_UPUP   1
  144. #define XPKMODE_UPSTD  2
  145. #define XPKMODE_UPPP   3
  146. #define XPKMODE_PKSTD  20
  147.  
  148. #define AUTO_PASS_SIZE    50
  149.  
  150. /* This is what XPK "handles" really point to */
  151. struct XpkBuffer {
  152.   struct XpkFib         xb_Fib;/* file info about this file        */
  153.   UWORD   xb_PackingMode;    /* desired packing efficiency, 0..100   */
  154.   struct Headers     xb_Headers;    /* global and local file header */
  155.   ULONG   xb_Format;        /* type of file                */
  156.   ULONG   xb_ChunkLen;        /* compressed chunk len            */
  157.   LONG    xb_Result;        /* error code from last call        */
  158. //  LONG    xb_Result2;        /* possible result from IoErr()        */
  159.   STRPTR  xb_ErrBuf;        /* Where user wants the error        */
  160.   STRPTR *xb_GetOutBuf;        /* Where user wants the out buf addr    */
  161.   ULONG  *xb_GetOutLen;        /* Where user wants the output len    */
  162.   ULONG  *xb_GetOutBufLen;    /* Where user wants the out buf len    */
  163.   ULONG   xb_ULen;        /* Uncompressed length of file        */
  164.   ULONG   xb_Secs;        /* Start time, the seconds        */
  165.   ULONG   xb_Mics;        /* Start time, the micros        */
  166.   struct Hook        *xb_RHook;    /* input data hook        */
  167.   struct Hook        *xb_WHook;    /* output data hook        */
  168.   struct Hook        *xb_ChunkHook;    /* Hook to call between chunks    */
  169.   STRPTR  xb_Password;        /* password for de/encoding        */
  170.   ULONG   xb_PasswordSize;    /* password buffer size for own password*/
  171.   ULONG   xb_SubPackMode;    /* Packing mode to be used        */
  172.   ULONG   xb_SubID;        /* ID of currently open sub        */
  173.   ULONG   xb_ChunkSize;        /* Chunk size to use for packing    */
  174.   ULONG   xb_FirstChunk;    /* Smallest chunk so far        */
  175.   ULONG   xb_MinChunk;        /* Minimum size of a chunk        */
  176.   ULONG   xb_Flags;        /* private for xpkmaster        */
  177.   LONG    xb_Priority;        /* task pri during packing        */
  178.   struct XpkInfo    *xb_SubInfo; /* Info of current open sub-lib    */
  179.   struct Library    *xb_SubBase; /* Currently open sub-library    */
  180.   LONG    xb_InLen;        /* Number of bytes to (un)pack        */
  181.   STRPTR  xb_InName;        /* InputName for prefs Recog func    */
  182.   ULONG   xb_OutLen;        /* Number of bytes written        */
  183.   ULONG   xb_OutMemType;    /* Type of memory for output buffer    */
  184.   STRPTR  xb_OutName;        /* Output file name            */
  185.   struct XpkMasterMsg      xb_RMsg; /* Parameters for reading        */
  186.   struct XpkMasterMsg     xb_WMsg; /* Parameters for writing        */
  187.   struct XpkSubParams     xb_PackParam;/* Parameters to (Un)PackChunk()    */
  188.   struct XpkProgress     xb_Prog; /* Parameters to progress report    */
  189.   STRPTR  xb_LastMsg;        /* The last progress message        */
  190. #ifdef SUPPORT_A4
  191.   ULONG      xb_regA4;
  192. #endif
  193. };
  194.  
  195. /* Values for MasterFlags */
  196. #define XMF_PRIVFH    (1<<0)    /* We opened the FH, so we close it.    */
  197. #define XMF_PACKING    (1<<1)    /* This is a packing operation.        */
  198. #define XMF_PASSTHRU    (1<<2)    /* Pass uncompressed data through    */
  199. #define XMF_GETOUTBUF    (1<<3)    /* Get output buffer when size known    */
  200. #define XMF_NOCLOBBER    (1<<4)    /* Don't overwrite            */
  201. #define XMF_EOF        (1<<5)    /* End of file                */
  202. #define XMF_IDSENT    (1<<6)    /* First four bytes of unpacked sent    */
  203. #define XMF_INITED    (1<<7)    /* Sublib buffers have been allocted    */
  204. #define XMF_GLOBHDR    (1<<8)    /* GlobHdr is already written        */
  205. #define XMF_LOSSYOK    (1<<9)    /* Lossy compression permitted        */
  206. #define XMF_OWNTASKPRI    (1<<10) /* Altered task pri, restore        */
  207. #define XMF_NOCRC    (1<<11)    /* Do not check the checksum on decomp    */
  208. #define XMF_USECOMMENT    (1<<12) /* Store FIB in file comment        */
  209. #define XMF_NOPREFS    (1<<13) /* Are prefs allowed ?            */
  210. #define XMF_XFD        (1<<14) /* Is XFD unpacking allowed ?        */
  211. #define XMF_EXTERNALS    (1<<15) /* Is extern allowed ?            */
  212. #define XMF_AUTOPASSWD    (1<<16) /* Automatic password            */
  213. #define XMF_AUTOPRHOOK  (1<<17) /* Automatic Progress hook        */
  214. #define XMF_NOPACK    (1<<18) /* destination file equals source    */
  215. #define XMF_OWNPASSWORD (1<<19) /* free password buffer later !!!    */
  216.  
  217. #ifdef DEBUG
  218. void     DebugError(STRPTR, ...);            // debug.c
  219. void     DebugRunTime(STRPTR, ...);            // debug.c
  220. void    DebugTagList(STRPTR, struct TagItem *);        // debug.c
  221. #endif
  222.  
  223. ULONG __asm MyCallHookPkt(register __a0 struct Hook *,
  224. register __a1 APTR A4PROTO);
  225.  
  226. extern struct DosLibrary       *DOSBase;        // libdata.a
  227. extern struct Hook        fhinhook;        // hook_fh.c
  228. extern struct Hook        fhouthook;        // hook_fh.c
  229. extern struct IntuitionBase    *IntuitionBase;        // libdata.a
  230. extern UBYTE            MainVersion;        // libdata.a
  231. extern struct Hook        meminhook;        // hook_mem.c
  232. extern struct Hook        memouthook;        // hook_mem.c
  233. extern struct ExecBase         *SysBase;        // libdata.a
  234. extern struct Library           *UtilityBase;        // libdata.a
  235. extern struct Library           *XpkBase;        // libdata.a
  236.  
  237. LONG    callprogress(struct XpkBuffer *);            // progress.c
  238. UWORD    cchecksum(ULONG *, ULONG);                // checksum.c
  239. void    closesub(struct XpkBuffer *);                // sublibs.c
  240. LONG    freebufs(struct XpkBuffer *);                // xbuf.h
  241. struct XpkPrefsSemaphore *GetPrefsSem(void);            // objects.c
  242. UBYTE    hchecksum(STRPTR, ULONG);                // checksum.c
  243. APTR    hookread(struct XpkBuffer *, ULONG, APTR, ULONG);    // hook.c
  244. APTR    hookwrite(struct XpkBuffer *, ULONG, APTR, ULONG);    // hook.c
  245. ULONG    idfromname(STRPTR);                    // util.c
  246. struct XpkBuffer    *initxbuf(void);            // xbuf.h
  247. struct Library        *opensub(struct XpkBuffer *, ULONG);    // sublibs.c
  248. LONG    parsebuftags(struct XpkBuffer*, struct TagItem*, ULONG);// tags.c
  249. void    parseerrortags(struct TagItem *);            // tags.c
  250. void    parsegettags(struct XpkBuffer *);            // tags.c
  251. void    percentages(struct XpkFib *);                // fib.c
  252. void    updatefib(struct XpkBuffer *);                // fib.c
  253. LONG    __asm xpkopen(   register __a0 struct XpkBuffer **,
  254.              register __a1 struct TagItem *,
  255.              register __d2 ULONG
  256.              A4PROTO);                // open.c
  257. LONG    xpkopenwrite(struct XpkBuffer **, struct TagItem *);    // open.c
  258.  
  259. #endif /* XPKMASTER_XPKMASTER_H */
  260.